<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span {
            display: block;
            width: 50px;
            height: 50px;
            text-align: center;
            line-height: 50px;
            float: left;
        }
    </style>
    <!-- 
        1000以内所有的素数(就是质数) 除了1和它本身没有其他因数。只能被1和它本身被整除
     -->
</head>

<body>
    <div id="dv">
        <p>1000以内所有的素数(就是质数) 除了1和它本身没有其他因数。只能被1和它本身被整除</p>
    </div>
</body>
<script>
    for (let i = 2; i < 1000; i++) {
        if (isPrimeNum(i)) {
            let spanObj = document.createElement('span');
            spanObj.innerText = i;
            document.getElementById('dv').appendChild(spanObj);
        }
    }

    function isPrimeNum(num) {
        let flag = true;
        for (let i = 2; i < parseInt(num / 2); i++) {
            if (num % i == 0) {
                flag = false;
            }
        }
        return flag;
    }
</script>

</html>